$(document).ready(function () {
			
			$("#chatBelt").click(function () {
              var bro = $.browser
              var chatBelt = document.getElementById("chatBelt");
              var isChatHidden = $("#chatBelt").css("z-index");
              if (isChatHidden == 11) {
                  if ($.browser.safari || $.browser.opera) {
                      chatBelt.setAttribute("style", "z-index: 10;");
                      $("#chatBox").animate({
                          bottom: '+=395'
                      }, 1200)
                  }
                  else {
                      chatBelt.setAttribute("style", "z-index: 10;");
                      $("#chatBox").animate({
                          bottom: '+=395'
                      }, 1200)
                  }
              }
              else {
                  if ($.browser.safari || $.browser.opera) {
                      chatBelt.setAttribute("style", "z-index: 11;");
                      $("#chatBox").animate({
                          bottom: '-=395'
                      }, 1200)
                  }
                  else {
                      chatBelt.setAttribute("style", "z-index: 11;");
                      $("#chatBox").animate({
                          bottom: '-=395'
                      }, 1200)
                  }
              }
			});
		  
		  $("#chatTextToSendField").keydown(function (event) {
              if (event.keyCode == 13) {
                  $("#chatSendButton").click();
              }
          });
		  
		  $(document).ready(function () {
            var chatBelt = document.getElementById("chatBelt");
            var isChatHidden = $("#chatBelt").css("z-index");
            var nick = "<%=Context.User.Identity.Name%>: ";
            $.connection.myTestChatHub.addMessage = function (msg) {
                $("#msgsContener").append(
                    $("<div></div>")
                        .addClass("singleChatMsg")
                        .append(
                            $("<p></p>")
                            .addClass("msgParagraph")
                                .append(
                                    $("<span></span>")
                                        .addClass("nick")
                                        .text(msg.Nick))
                    .append(msg.Message))
                        .append(
                           $("<div></div>")
                               .addClass("date")
                               .text("<%=DateTime.Now.ToShortTimeString()%>")));
                var isChatHidden = $("#chatBelt").css("z-index");
                if (isChatHidden == 11) { //11 means it IS hidden
                    chatBelt.setAttribute("style", "background-color: red; color: white; border: 0px solid Red;");  //notyfing if chat is hidden
                }
                var elem = document.getElementById('msgsContener');
                elem.scrollTop = elem.scrollHeight;                     //auto scrolling 

            };
            $("#chatSendButton").click(function () {
                var regex = /^\s*$/;
                if (!regex.test($("#chatTextToSendField").val())) {
                    $.connection.myTestChatHub.sendMessage(nick, $("#chatTextToSendField").val()); //sending to chat window 
                    $("#chatTextToSendField").val("");
                }
            });
            $.connection.hub.start();
        });
		  
	});  
		